package tenumn.energytech.registrys.recipe;

import com.google.gson.JsonObject;
import io.github.uicdb.liba.api.register.LazyRecipeSerializer;
import io.github.uicdb.liba.api.register.RecipeHolder;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import tenumn.energytech.registrys.RecipeRegistry;

import javax.annotation.Nonnull;

public class MillingRecipe extends OneToTwoRecipe{
    public MillingRecipe(Ingredient input, ItemStack outFirst, ItemStack outSecond, double secondChance) {
        super(input, outFirst, outSecond, secondChance);
    }

    @Nonnull
    @Override
    protected RecipeHolder<?> getRecipeHolder() {
        return RecipeRegistry.MILLING;
    }
    public static final class Ser extends LazyRecipeSerializer<MillingRecipe> {

        @Override
        public MillingRecipe fromJson(ResourceLocation pRecipeId, JsonObject pSerializedRecipe) {
            var result = GSON.fromJson(pSerializedRecipe, MillingRecipe.class);
            result.setId(pRecipeId);
            return result;
        }

        @Nonnull
        @Override
        public MillingRecipe fromNetwork(ResourceLocation pRecipeId, FriendlyByteBuf pBuffer) {
            var result = GSON.fromJson(pBuffer.readUtf(), MillingRecipe.class);
            result.setId(pRecipeId);
            return result;
        }

        @Override
        public void toNetwork(FriendlyByteBuf pBuffer, MillingRecipe pRecipe) {
            pBuffer.writeUtf(GSON.toJson(pRecipe));
        }
    }
}
